from etx import db
from sqlalchemy import Column, Integer, String


class ModelBase(object):

    def to_json(self):
        fields = self.__dict__
        if "_sa_instance_state" in fields:
            del fields["_sa_instance_state"]
        return fields


class User(db.Model, ModelBase):
    # 数据库表名
    __tablename__ = 'user'
    id = Column(Integer, primary_key=True, autoincrement=True)
    username = Column(String(255))
    sex = Column(String(255))
    email = Column(String(255))
    password = Column(String(255))

    def __init__(self, username: str, sex: str, email: str, password: str):
        self.username = username
        self.sex = sex
        self.email = email
        self.password = password

